package com.grupoconstruobras.sigo.exhumaciones.ui.validator;

import java.util.Date;
import java.util.ResourceBundle;

import javax.faces.application.FacesMessage;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.validator.FacesValidator;
import javax.faces.validator.Validator;
import javax.faces.validator.ValidatorException;

@FacesValidator("notAfterToday")
public class NotAfterTodayValidator implements Validator {
	
private ResourceBundle bundle;
	
	public NotAfterTodayValidator() {
		FacesContext fc = FacesContext.getCurrentInstance();
		bundle = fc.getApplication().evaluateExpressionGet(fc, "#{msgVal}", ResourceBundle.class);
	}

    public void validate(FacesContext context, UIComponent component, Object value) throws ValidatorException {
        
    	Date date = (Date) value;
        Date today = new Date();

        if (date.after(today)) {        	
            String msg = bundle.getString("exhumaciones.diligencia.fechaTraslado.igualomenor");
			FacesMessage message = new FacesMessage(FacesMessage.SEVERITY_ERROR, msg, null);
			context.addMessage(component.getClientId(), message);            
			throw new ValidatorException(message);
        }
    }
}